package edu.scut.course_management.dto;

import java.util.HashMap;
import java.util.Map;

import edu.scut.course_management.po.Teacher;

/**
 * 
 * @author sherry
 */
public class RequestTeacherDTO {
    private String teacherId;
    private String name;
    private Boolean male;
    private String phoneNumber;
    private Integer departmentId;
    private String academicTitle;

    public RequestTeacherDTO(String teacherId, String name, Boolean male, String phoneNumber, Integer departmentId, String academicTitle) {
        this.teacherId = teacherId;
        this.name = name;
        this.male = male;
        this.phoneNumber = phoneNumber;
        this.departmentId = departmentId;
        this.academicTitle = academicTitle;
    }

    public RequestTeacherDTO() {
    }

    public String getTeacherId() {
        return teacherId;
    }

    public void setTeacherId(String teacherId) {
        this.teacherId = teacherId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isMale() {
        return male;
    }

    public void setMale(boolean male) {
        this.male = male;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public Integer getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(Integer departmentId) {
        this.departmentId = departmentId;
    }

    public String getAcademicTitle() {
        return academicTitle;
    }

    public void setAcademicTitle(String academicTitle) {
        this.academicTitle = academicTitle;
    }

    public boolean checkParamValidity(boolean isAdd) {
        // 新增用户的参数检测
        if (isAdd) {
            if (teacherId.length() != 9) {
                return false;
            }
            else if (name == null || name.trim().isEmpty()) {
                return false;
            }
            else if (male == null) {
                return false;
            }
            else if (departmentId == null) {
                return false;
            }
            else if (academicTitle == null || academicTitle.trim().isEmpty()) {
                return false;
            }
            else {
                return true;
            }
        }
        // 查询用户信息的参数检测
        else {
            // 至少有一个查询条件
            if ((teacherId != null && !teacherId.trim().isEmpty()) || (name != null && !name.trim().isEmpty()) ||
                (departmentId != null) || (academicTitle != null && !academicTitle.trim().isEmpty())) {
                return true;
            }
            else {
                return false;
            }
        }
    }

    // 新增教师对象
    public Teacher toObjectTeacher() {
        return new Teacher (2, teacherId, null, name, male, 
                phoneNumber, departmentId, academicTitle);
    }


    // 查询教师信息条件
    public Map<String, Object> queryTeacher () {
        Map<String, Object> map = new HashMap<>();
        map.put("teacherId", teacherId);
        map.put("name", name);
        map.put("departmentId", departmentId);
        map.put("academicTitle", academicTitle);
        return map;
    }
    
}
